package com.hsnn.medstgmini.base.std.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.hibernate.annotations.Source;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.hsnn.medstgmini.base.std.model.StdExpert;
import com.hsnn.medstgmini.base.std.model.StdExpertLog;
import com.hsnn.medstgmini.base.std.service.StdExpertLogManager;
import com.hsnn.medstgmini.model.Result;


/**
 *  专家维护记录库
 */
@Controller
@RequestMapping("/stdExpertLog")
public class StdExpertLogController {

	@Source
	private StdExpertLogManager stdExpertLogManager;
	
	@Autowired
	public void setStdExpertLogManager(StdExpertLogManager stdExpertLogManager){
		this.stdExpertLogManager = stdExpertLogManager;
	}
	
	
	/**
	 * 跳转到专家维护页面
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
	@RequestMapping(value="/sel",method={RequestMethod.GET,RequestMethod.POST})
	public String  sel(HttpServletRequest request,HttpServletResponse response) throws IOException {
		return "/base/std/stdExpertLogList";
	}
	
	/**到专家维护查询list及条件查询
	 * @param request
	 * @param result
	 * @return
	 */
	@RequestMapping("SelectStdExpertLog")
	@ResponseBody
	public Result SelectStdExpertLog(HttpServletRequest request, Result result) {
		result = result == null ? new Result() : result;
		StdExpertLog stdExpertLog = new StdExpertLog();
		try{
			String expertCode = request.getParameter("expertCode");
			String name = request.getParameter("name");
			String expSkills = request.getParameter("expSkills");
			String companyId = request.getParameter("companyId");
			String sex = request.getParameter("sex");
			stdExpertLog.setExpertCode(expertCode);
			stdExpertLog.setName(name);
			stdExpertLog.setExpSkills(expSkills);
			stdExpertLog.setCompanyId(companyId);
			stdExpertLog.setSex(sex);
			List<StdExpertLog> list = stdExpertLogManager.SelectStdExpertLogList(result, stdExpertLog);
			JSONArray jsonarray = (JSONArray) JSONArray.toJSON(list);
			result.setRecords(list.size());
			result.setRows(list);
		} catch (Exception e) {
			e.printStackTrace();
			result.setType(Result.FAILED);
		} catch(Error error) {
			error.printStackTrace();
			result.setType(Result.FAILED);
		}
		return result;
	}

}
